package org.training.apr.service.impl;

import javax.jws.WebService;

import org.training.apr.Application;
import org.training.apr.dao.UserDao;
import org.training.apr.dto.UserDto;
import org.training.apr.service.UserService;

@WebService
@SuppressWarnings("serial")
public class UserServiceImpl extends Service implements UserService {
	private UserDao dao;
	
	public UserServiceImpl() {
		this(Application.getServiceFactory().getDaoFactory().createUserDao());
	}

	public UserServiceImpl(UserDao dao) {
		this.dao = dao;
	}

	public UserDto readByUsername(String username) {
		return mapper.toDto(dao.readByUsername(username));
	}

	public UserDto login(String username, String password) {
		UserDto user = readByUsername(username);
		
		if(user != null && user.getPassword().equals(password)) {
			return user; 
		}
		
		return null;
	}

}
